<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="canvas," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.2" />






<meta name="description" content="什么是canvas 是一个元素 HTML5元素 画布 本身没有回话功能，需要通过 javascript 来实现 默认大小是  300*150 设置宽高不要在 css 里面设置；因为在哪里设置只是拉伸，写位置时还是按照 300*150 进行定位 设置宽高 &amp;lt;canvas height=&amp;quot;300&amp;quot; width=&amp;quot;600&amp;quot;&amp;gt;&amp;lt;/canvas&amp;gt">
<meta name="keywords" content="canvas">
<meta property="og:type" content="article">
<meta property="og:title" content="canvas">
<meta property="og:url" content="http://yoursite.com/2017/09/13/canvas/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="什么是canvas 是一个元素 HTML5元素 画布 本身没有回话功能，需要通过 javascript 来实现 默认大小是  300*150 设置宽高不要在 css 里面设置；因为在哪里设置只是拉伸，写位置时还是按照 300*150 进行定位 设置宽高 &amp;lt;canvas height=&amp;quot;300&amp;quot; width=&amp;quot;600&amp;quot;&amp;gt;&amp;lt;/canvas&amp;gt">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://developer.mozilla.org/@api/deki/files/85/=Canvas_grid_translate.png">
<meta property="og:image" content="https://developer.mozilla.org/@api/deki/files/84/=Canvas_grid_rotate.png">
<meta property="og:image" content="http://yoursite.com/img/scale.jpg">
<meta property="og:image" content="http://yoursite.com/img/save.jpg">
<meta property="og:image" content="http://yoursite.com/img/restore.jpg">
<meta property="og:updated_time" content="2017-09-20T07:23:13.769Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="canvas">
<meta name="twitter:description" content="什么是canvas 是一个元素 HTML5元素 画布 本身没有回话功能，需要通过 javascript 来实现 默认大小是  300*150 设置宽高不要在 css 里面设置；因为在哪里设置只是拉伸，写位置时还是按照 300*150 进行定位 设置宽高 &amp;lt;canvas height=&amp;quot;300&amp;quot; width=&amp;quot;600&amp;quot;&amp;gt;&amp;lt;/canvas&amp;gt">
<meta name="twitter:image" content="https://developer.mozilla.org/@api/deki/files/85/=Canvas_grid_translate.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.2',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2017/09/13/canvas/"/>





  <title>canvas | Hexo</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Hexo</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/09/13/canvas/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="shine-wl">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="http://dynamic-image.yesky.com/300x-/uploadImages/upload/20140912/upload/201409/wylnwjynkxijpg.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Hexo">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">canvas</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-13T11:23:03+08:00">
                2017-09-13
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="什么是canvas"><a href="#什么是canvas" class="headerlink" title="什么是canvas"></a>什么是canvas</h3><ol>
<li>是一个元素 HTML5元素</li>
<li>画布 本身没有回话功能，需要通过 javascript 来实现</li>
<li>默认大小是  300*150</li>
<li>设置宽高不要在 css 里面设置；因为在哪里设置只是拉伸，写位置时还是按照 300*150 进行定位</li>
<li>设置宽高 <code>&lt;canvas height=&quot;300&quot; width=&quot;600&quot;&gt;&lt;/canvas&gt;</code>这样进行设置</li>
<li>在浏览器解析的时候，会解析成图片</li>
</ol>
<p>模板：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">&lt;body&gt;</div><div class="line">&lt;canvas width=<span class="string">"600"</span> height=<span class="string">"400"</span>&gt;<span class="xml"><span class="tag">&lt;/<span class="name">canvas</span>&gt;</span></span></div><div class="line">&lt;script&gt;</div><div class="line">    <span class="keyword">var</span> canvas = <span class="built_in">document</span>.querySelector(<span class="string">'canvas'</span>);</div><div class="line">    <span class="keyword">var</span> ctx = canvas.getContext(<span class="string">'2d'</span>);</div><div class="line">    </div><div class="line">   ....(要实现的内容)</div><div class="line">   </div><div class="line">&lt;<span class="regexp">/script&gt;</span></div><div class="line"><span class="regexp">&lt;/</span>body&gt;</div></pre></td></tr></table></figure></p>
<a id="more"></a>
<h3 id="canvas中的方法和属性"><a href="#canvas中的方法和属性" class="headerlink" title="canvas中的方法和属性"></a>canvas中的方法和属性</h3><p>注意： 这里只是将属性和方法列举了出来具体的解释在下面，请往下阅读–</p>
<ul>
<li>getContext() —获取绘制环境</li>
<li>moveTo() ——设置起始绘制图位置</li>
<li>lineTo() ——–绘制路径</li>
<li>stroke() ——–描边</li>
<li>fill() ————填充颜色，默认是黑色</li>
<li>setLineDash() –设置虚线</li>
<li>getLineDash() –获取虚线宽度集合</li>
<li>beginPath() —-开辟新的路径</li>
<li>closePath() —–关闭路径</li>
</ul>
<ul>
<li>strokeStyle ——设置描边的颜色</li>
<li>fillStyle ———-设置填充的颜色</li>
<li>lineWidth ——-设置线的宽度</li>
<li>lineCap ———-设置线两端的样式</li>
<li>lineJoin ———-设置线拐点的样式</li>
<li>lineDashOffset —设置虚线偏移量（负值向右偏移）</li>
</ul>
<h3 id="绘制的基本步骤"><a href="#绘制的基本步骤" class="headerlink" title="绘制的基本步骤"></a>绘制的基本步骤</h3><ol>
<li><p>获取 canvas 元素</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> canvas=<span class="built_in">document</span>.querySelector(<span class="string">'canvas'</span>)</div></pre></td></tr></table></figure>
</li>
<li><p>获取绘制环境 （获取绘制工具）</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> ctx = canvas.getContext(<span class="string">'2d'</span>);</div></pre></td></tr></table></figure>
</li>
<li><p>设置起始绘图的位置</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ctx.moveTo(<span class="number">100</span>,<span class="number">100</span>);</div></pre></td></tr></table></figure>
</li>
<li><p>绘制路径</p>
</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ctx.lineTo(<span class="number">200</span>,<span class="number">100</span>);</div></pre></td></tr></table></figure>
<ol>
<li>描边 相当于上上色一样不然不会显示</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ctx.stroke();</div></pre></td></tr></table></figure>
<h3 id="绘制线条"><a href="#绘制线条" class="headerlink" title="绘制线条"></a>绘制线条</h3><h4 id="设置样式"><a href="#设置样式" class="headerlink" title="设置样式"></a>设置样式</h4><ul>
<li>画笔的状态<ul>
<li>lineWidth 线宽，默认1px</li>
<li>lineCap 线末端类型：(butt默认)、round（圆）、square （正方形）</li>
<li>lineJoin 相交线的拐点 miter(默认)、round（圆）、bevel（切线）</li>
<li>strokeStyle 线的颜色</li>
<li>fillStyle 填充颜色</li>
<li>setLineDash() 设置虚线</li>
<li>getLineDash() 获取虚线宽度集合</li>
<li>lineDashOffset 设置虚线偏移量（负值向右偏移）</li>
</ul>
</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/*1.获取canvas元素*/</span></div><div class="line"><span class="keyword">var</span> canvas = <span class="built_in">document</span>.querySelector(<span class="string">'canvas'</span>);</div><div class="line"><span class="comment">/*2.获取绘制环境  （获取绘制工具）*/</span></div><div class="line"><span class="comment">/*content内容  context 上下文 */</span></div><div class="line"><span class="keyword">var</span> ctx = canvas.getContext(<span class="string">'2d'</span>);</div><div class="line"><span class="comment">/*3.设置起始绘图的位置*/</span></div><div class="line">ctx.moveTo(<span class="number">100</span>,<span class="number">100</span>);</div><div class="line"><span class="comment">/*6.设置宽度*/</span></div><div class="line">ctx.lineWidth = <span class="number">10</span>;</div><div class="line"><span class="comment">/*4.绘制路径 */</span></div><div class="line">ctx.lineTo(<span class="number">200</span>,<span class="number">100</span>);</div><div class="line"><span class="comment">/*7. 设置描边的颜色*/</span></div><div class="line">ctx.strokeStyle = <span class="string">'red'</span>;</div><div class="line"><span class="comment">/*5.描边*/</span></div><div class="line">ctx.stroke();</div></pre></td></tr></table></figure>
<ul>
<li>为什么线会变粗变浅？</li>
</ul>
<ol>
<li>线 默认是1px 黑色的</li>
<li>canvas 是由像素点构成的</li>
<li>绘制的时候 以坐标中心进行绘制 也就是1像素的中间 以至于吧1像素分成了2个0.5</li>
<li>但是浏览器无法显示0.5像素 所以就把0.5像素放在了1像素中进行显示就被拉伸了，所以才会变宽变浅</li>
</ol>
<h4 id="ctx-beginPath-开辟新的路径"><a href="#ctx-beginPath-开辟新的路径" class="headerlink" title="ctx.beginPath() 开辟新的路径"></a>ctx.beginPath() 开辟新的路径</h4><ul>
<li>没有设置时会使用上面的样式 改变下面的样式会影响上面的把上面的样式覆盖</li>
<li>开辟新路径之后 如果不设置新的样式 会使用上面的样式  设置了就使用自己的但不会影响上面<ul>
<li>案例设置两条不同颜色的平行线</li>
</ul>
</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// 1 获取canvas元素</span></div><div class="line">   <span class="keyword">var</span> canvas=<span class="built_in">document</span>.querySelector(<span class="string">'canvas'</span>);</div><div class="line">   <span class="comment">// 2 获取绘制环境  （获取绘制工具）</span></div><div class="line">   <span class="keyword">var</span> ctx=canvas.getContext(<span class="string">'2d'</span>);</div><div class="line">   <span class="comment">// 3 设置其实绘图的位置</span></div><div class="line">   ctx.moveTo(<span class="number">100</span>,<span class="number">100</span>);</div><div class="line">   <span class="comment">// 4 绘制路径</span></div><div class="line">   ctx.lineTo(<span class="number">200</span>,<span class="number">100</span>);</div><div class="line">   <span class="comment">// 6 设置宽度</span></div><div class="line">   ctx.lineWidth=<span class="number">10</span>;</div><div class="line">   <span class="comment">// 7设置描边颜色</span></div><div class="line">   ctx.strokeStyle=<span class="string">'red'</span>;</div><div class="line">   <span class="comment">// 5 描边</span></div><div class="line">   ctx.stroke();</div><div class="line"></div><div class="line">   <span class="comment">// 开辟新路径</span></div><div class="line">   ctx.beginPath();</div><div class="line">   ctx.moveTo(<span class="number">100</span>,<span class="number">200</span>);</div><div class="line">   ctx.lineTo(<span class="number">200</span>,<span class="number">200</span>);</div><div class="line">   ctx.strokeStyle=<span class="string">'green'</span>;</div></pre></td></tr></table></figure>
<h4 id="绘制三角形"><a href="#绘制三角形" class="headerlink" title="绘制三角形"></a>绘制三角形</h4><h5 id="ctx-closePath-关闭路径"><a href="#ctx-closePath-关闭路径" class="headerlink" title="ctx.closePath() 关闭路径"></a>ctx.closePath() 关闭路径</h5><ul>
<li><p>手动关闭</p>
<ul>
<li>会出现部分部位 不能完全链接的情况<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// 1 获取canvas元素</span></div><div class="line">   <span class="keyword">var</span> canvas=<span class="built_in">document</span>.querySelector(<span class="string">'canvas'</span>);</div><div class="line">   <span class="comment">// 2 获取绘制环境  （获取绘制工具）</span></div><div class="line">   <span class="keyword">var</span> ctx=canvas.getContext(<span class="string">'2d'</span>);</div><div class="line">   <span class="comment">// 3 设置其实绘图的位置</span></div><div class="line">   ctx.moveTo(<span class="number">100</span>,<span class="number">100</span>);</div><div class="line">   ctx.lineTo(<span class="number">200</span>,<span class="number">100</span>);</div><div class="line">   ctx.lineTo(<span class="number">200</span>,<span class="number">200</span>);</div><div class="line">   <span class="comment">//手动闭合   会出现部分部位 不能完全链接的情况</span></div><div class="line">   ctx.lineTo(<span class="number">100</span>,<span class="number">100</span>);</div><div class="line">   ctx.lineWidth=<span class="number">10</span>;</div><div class="line">   ctx.strokeStyle=<span class="string">'red'</span>;</div></pre></td></tr></table></figure>
</li>
</ul>
</li>
<li><p>自动关闭 ctx.closePath()</p>
<ul>
<li>自动闭合 不会出现部分部位 不能完全链接的情况</li>
</ul>
</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// 1 获取canvas元素</span></div><div class="line">   <span class="keyword">var</span> canvas=<span class="built_in">document</span>.querySelector(<span class="string">'canvas'</span>);</div><div class="line">   <span class="comment">// 2 获取绘制环境  （获取绘制工具）</span></div><div class="line">   <span class="keyword">var</span> ctx=canvas.getContext(<span class="string">'2d'</span>);</div><div class="line">   <span class="comment">// 3 设置其实绘图的位置</span></div><div class="line">   ctx.moveTo(<span class="number">100</span>,<span class="number">100</span>);</div><div class="line">   ctx.lineTo(<span class="number">200</span>,<span class="number">100</span>);</div><div class="line">   ctx.lineTo(<span class="number">200</span>,<span class="number">200</span>);</div><div class="line">   ctx.closePath();</div><div class="line">   ctx.stroke();</div><div class="line">   <span class="comment">// 描边不描边不会影响 填充</span></div><div class="line">   ctx.fill();</div></pre></td></tr></table></figure>
<h4 id="填充-ctx-fill"><a href="#填充-ctx-fill" class="headerlink" title="填充 ctx.fill()"></a>填充 ctx.fill()</h4><ul>
<li>填充规则 ：非零绘制规则<ol>
<li>看某块区域是否被填充</li>
<li>从这个区域拉一条线穿过边框</li>
<li>计算每条线的值 逆时针 -1  顺时针 +1</li>
<li>加一块  如果是非零的那么就填充  否则不填充<h4 id="线两端的样式和线拐点的样式"><a href="#线两端的样式和线拐点的样式" class="headerlink" title="线两端的样式和线拐点的样式"></a>线两端的样式和线拐点的样式</h4>线两端<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">ctx.lineCap = &apos;butt&apos;; //默认</div><div class="line">ctx.lineCap = &apos;round&apos;; //圆形</div><div class="line">ctx.lineCap = &apos;square&apos;; //正方形</div></pre></td></tr></table></figure>
</li>
</ol>
</li>
</ul>
<p>线拐点</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">ctx.lineJoin = &apos;miter&apos;; //默认</div><div class="line">ctx.lineJoin = &apos;round&apos;; //圆</div><div class="line">ctx.lineJoin = &apos;bevel&apos;; //切线</div></pre></td></tr></table></figure>
<h4 id="绘制虚线"><a href="#绘制虚线" class="headerlink" title="绘制虚线"></a>绘制虚线</h4><ul>
<li>设置虚线  ctx.setLineDash()<ul>
<li>传数组 ctx.setLineDash([5, 3, 1]) </li>
<li>设置虚线的宽度和长度</li>
</ul>
</li>
<li>获取虚线的 ctx.getLineDash()<ul>
<li>偶数个获取的是数组中的数  [5,3]</li>
<li>奇数个获取的是两组数字中的数 [5,3,1,5,3,1]</li>
<li>获取的是不重复的一段</li>
</ul>
</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> canvas = <span class="built_in">document</span>.querySelector(<span class="string">'canvas'</span>)</div><div class="line">        <span class="keyword">var</span> ctx = canvas.getContext(<span class="string">'2d'</span>)</div><div class="line">        ctx.moveTo(<span class="number">100</span>, <span class="number">100</span>)</div><div class="line">        ctx.lineTo(<span class="number">200</span>, <span class="number">100</span>)</div><div class="line">        ctx.lineWidth = <span class="number">10</span></div><div class="line">            <span class="comment">//设置虚线的方法</span></div><div class="line">            <span class="comment">//传数组 设置虚线的宽度和长度</span></div><div class="line"></div><div class="line">        <span class="comment">// ctx.setLineDash([5, 3])</span></div><div class="line">        ctx.setLineDash([<span class="number">5</span>, <span class="number">3</span>, <span class="number">1</span>])</div><div class="line">        ctx.stroke()</div><div class="line">            <span class="comment">//获取虚线的方法</span></div><div class="line">            <span class="comment">// 偶数个获取的是数组中的数  [5,3]</span></div><div class="line">            <span class="comment">// 奇数个获取的是两组数字中的数 [5,3,1,5,3,1]</span></div><div class="line">            <span class="comment">// 获取的是不重复的一段</span></div><div class="line">        <span class="built_in">console</span>.log(ctx.getLineDash())</div></pre></td></tr></table></figure>
<h3 id="绘制矩形"><a href="#绘制矩形" class="headerlink" title="绘制矩形"></a>绘制矩形</h3><h4 id="ctx-rect-100-100-200-100"><a href="#ctx-rect-100-100-200-100" class="headerlink" title="ctx.rect(100,100,200,100);"></a>ctx.rect(100,100,200,100);</h4><pre><code>+ 参数：1、canvas x轴坐标 2、canvas y轴坐标 3、矩形宽度 4、矩形高度
</code></pre><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> canvas = <span class="built_in">document</span>.querySelector(<span class="string">'canvas'</span>);</div><div class="line"><span class="keyword">var</span> ctx = canvas.getContext(<span class="string">'2d'</span>);</div><div class="line"><span class="comment">// 第一个参数 x轴坐标</span></div><div class="line"><span class="comment">// 第二个参数 y轴坐标</span></div><div class="line"><span class="comment">// 矩形宽度</span></div><div class="line"><span class="comment">// 矩形高度</span></div><div class="line">ctx.rect(<span class="number">100</span>,<span class="number">100</span>,<span class="number">200</span>,<span class="number">100</span>);</div><div class="line"><span class="comment">//描边</span></div><div class="line">ctx.stroke();</div><div class="line"><span class="comment">// 颜色填充</span></div><div class="line">ctx.fill();</div></pre></td></tr></table></figure>
<h4 id="ctx-strokeRect-100-100-200-100"><a href="#ctx-strokeRect-100-100-200-100" class="headerlink" title="ctx.strokeRect(100,100,200,100);"></a>ctx.strokeRect(100,100,200,100);</h4><pre><code>不用进行描边 有自己独立的路径并且绘制了的矩形
</code></pre><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> canvas = <span class="built_in">document</span>.querySelector(<span class="string">'canvas'</span>);</div><div class="line"><span class="keyword">var</span> ctx = canvas.getContext(<span class="string">'2d'</span>);</div><div class="line"><span class="comment">// 第一个参数 x轴坐标</span></div><div class="line"><span class="comment">// 第二个参数 y轴坐标</span></div><div class="line"><span class="comment">// 矩形宽度</span></div><div class="line"><span class="comment">// 矩形高度</span></div><div class="line">ctx.strokeRect(<span class="number">100</span>,<span class="number">100</span>,<span class="number">200</span>,<span class="number">100</span>);</div><div class="line"><span class="comment">// 颜色填充</span></div><div class="line">ctx.fill();</div></pre></td></tr></table></figure>
<h4 id="ctx-fillRect-100-100-200-100"><a href="#ctx-fillRect-100-100-200-100" class="headerlink" title="ctx.fillRect(100,100,200,100);"></a>ctx.fillRect(100,100,200,100);</h4><pre><code>不用进行描边 有自己独立的路径并且填充了的，绘制了的矩形
</code></pre><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> canvas = <span class="built_in">document</span>.querySelector(<span class="string">'canvas'</span>);</div><div class="line"><span class="keyword">var</span> ctx = canvas.getContext(<span class="string">'2d'</span>);</div><div class="line"><span class="comment">// 第一个参数 x轴坐标</span></div><div class="line"><span class="comment">// 第二个参数 y轴坐标</span></div><div class="line"><span class="comment">// 矩形宽度</span></div><div class="line"><span class="comment">// 矩形高度</span></div></pre></td></tr></table></figure>
<ul>
<li>ctx.fillRect(x,y,width,height);<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">x	要清除的矩形左上角的 x 坐标</div><div class="line">y	要清除的矩形左上角的 y 坐标</div><div class="line">width	要清除的矩形的宽度，以像素计</div><div class="line">height	要清除的矩形的高度，以像素计</div></pre></td></tr></table></figure>
</li>
</ul>
<h4 id="ctx-clearRect-0-0-600-400-清除矩形"><a href="#ctx-clearRect-0-0-600-400-清除矩形" class="headerlink" title="ctx.clearRect(0, 0, 600, 400); 清除矩形"></a>ctx.clearRect(0, 0, 600, 400); 清除矩形</h4><h3 id="绘制渐变"><a href="#绘制渐变" class="headerlink" title="绘制渐变"></a>绘制渐变</h3><h4 id="createLinearGradient"><a href="#createLinearGradient" class="headerlink" title="createLinearGradient()"></a>createLinearGradient()</h4><p> 创建线性的渐变对象   </p>
<p>渐变可用于填充矩形、圆形、线条、文本等等</p>
<h4 id="addColorStop"><a href="#addColorStop" class="headerlink" title="addColorStop()"></a>addColorStop()</h4><p> 方法规定渐变对象中的颜色和位置</p>
<p> 注意：您可以多次调用 addColorStop() 方法来改变渐变。如果您不对渐变对象使用该方法，那么渐变将不可见。为了获得可见的渐变，您需要创建至少一个色标。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> canvas = <span class="built_in">document</span>.querySelector(<span class="string">'canvas'</span>);</div><div class="line"><span class="keyword">var</span> ctx = canvas.getContext(<span class="string">'2d'</span>);</div><div class="line"></div><div class="line"><span class="comment">/*渐变的方案*/</span></div><div class="line"><span class="comment">// 第一个参数 x轴渐变开始的坐标</span></div><div class="line"><span class="comment">// 第二个参数 y轴渐变开始的坐标</span></div><div class="line"><span class="comment">// 第一个参数 x轴渐变结束的坐标</span></div><div class="line"><span class="comment">// 第二个参数 y轴渐变结束的坐标</span></div><div class="line"><span class="keyword">var</span> linearGradient = ctx.createLinearGradient(<span class="number">100</span>,<span class="number">150</span>,<span class="number">300</span>,<span class="number">150</span>);</div><div class="line"><span class="comment">// 这里 0-1 相当于css3中的 0-100%</span></div><div class="line">linearGradient.addColorStop(<span class="number">0</span>,<span class="string">'red'</span>);</div><div class="line">linearGradient.addColorStop(<span class="number">0.5</span>,<span class="string">'blue'</span>);</div><div class="line">linearGradient.addColorStop(<span class="number">1</span>,<span class="string">'yellow'</span>);</div><div class="line"></div><div class="line">ctx.fillStyle = linearGradient;</div><div class="line"></div><div class="line">ctx.fillRect(<span class="number">100</span>,<span class="number">100</span>,<span class="number">200</span>,<span class="number">100</span>);</div></pre></td></tr></table></figure></p>
<ul>
<li>自己封装颜色渐变<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">ctx.lineWidth = <span class="number">10</span>;</div><div class="line">  <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; <span class="number">255</span>; i++) &#123;</div><div class="line">      ctx.beginPath();</div><div class="line">      ctx.moveTo(<span class="number">99</span>+i,<span class="number">100</span>);</div><div class="line">      ctx.lineTo(<span class="number">100</span>+i,<span class="number">100</span>);</div><div class="line">      <span class="keyword">var</span> g = <span class="number">255</span> - i;</div><div class="line">      <span class="keyword">var</span> b = <span class="number">255</span> - i;</div><div class="line">      ctx.strokeStyle = <span class="string">'rgb(255,'</span>+g+<span class="string">','</span>+b+<span class="string">')'</span>;</div><div class="line">      ctx.stroke();</div><div class="line">  &#125;</div></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="绘制曲线"><a href="#绘制曲线" class="headerlink" title="绘制曲线"></a>绘制曲线</h3><p>示例：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> canvas = <span class="built_in">document</span>.querySelector(<span class="string">'canvas'</span>)</div><div class="line"><span class="keyword">var</span> ctx = canvas.getContext(<span class="string">'2d'</span>)</div><div class="line"><span class="keyword">var</span> con = <span class="built_in">Math</span>.cos(<span class="number">0</span> / <span class="number">20</span>) * <span class="number">100</span> + <span class="number">200</span>;</div><div class="line"><span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; <span class="number">600</span>; i++) &#123;</div><div class="line">    <span class="keyword">var</span> x = i</div><div class="line"></div><div class="line">    <span class="comment">// var y = Math.pow(x + 1, 2) / 600</span></div><div class="line">    <span class="keyword">var</span> y = <span class="built_in">Math</span>.cos((x + <span class="number">1</span>) / <span class="number">20</span>) * <span class="number">100</span> + <span class="number">200</span>;</div><div class="line">    ctx.beginPath();</div><div class="line">    ctx.moveTo(x, con);</div><div class="line">    ctx.lineTo(x + <span class="number">1</span>, y);</div><div class="line">    ctx.stroke();</div><div class="line">    con = y;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<h3 id="绘制圆弧"><a href="#绘制圆弧" class="headerlink" title="绘制圆弧"></a>绘制圆弧</h3><ul>
<li>ctx.arc(x0, y0, 150, 0, -Math.PI / 2, true);</li>
<li><ul>
<li>参数</li>
</ul>
<ol>
<li>圆中心 x 坐标</li>
<li>圆中心 y 坐标</li>
<li>圆中半径</li>
<li>起始的弧度</li>
<li>结束弧度</li>
<li>是顺时针还是逆时针 默认是 false 顺时针    true 逆时针</li>
</ol>
</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> canvas = <span class="built_in">document</span>.querySelector(<span class="string">'canvas'</span>);</div><div class="line"><span class="keyword">var</span> ctx = canvas.getContext(<span class="string">'2d'</span>);</div><div class="line"><span class="keyword">var</span> x0 = ctx.canvas.width / <span class="number">2</span>;</div><div class="line"><span class="keyword">var</span> y0 = ctx.canvas.height / <span class="number">2</span>;</div><div class="line"><span class="comment">// ctx.moveTo(x0, y0);</span></div><div class="line"><span class="comment">//绘制圆弧</span></div><div class="line">ctx.arc(x0, y0, <span class="number">150</span>, <span class="number">0</span>, -<span class="built_in">Math</span>.PI / <span class="number">2</span>, <span class="literal">true</span>);</div><div class="line"><span class="comment">//关闭路径</span></div><div class="line"><span class="comment">// ctx.closePath();</span></div><div class="line"><span class="comment">//描边</span></div><div class="line">ctx.stroke();</div><div class="line"><span class="comment">//填充</span></div><div class="line"><span class="comment">// ctx.fill();</span></div></pre></td></tr></table></figure>
<h3 id="绘制文字"><a href="#绘制文字" class="headerlink" title="绘制文字"></a>绘制文字</h3><ul>
<li><p>ctx.font = ‘40px 楷体’ 设置字体样式</p>
</li>
<li><p>ctx.strokeStyle = ‘red’; 设置字体颜色</p>
</li>
<li><p>ctx.textAlign = ‘left’; 设置文字左右对齐</p>
<ul>
<li>参数：top bottom right canter</li>
</ul>
</li>
<li><p>ctx.textBaseline = ‘bottom’; 设置文字上下对齐</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">ctx.textBaseline 设置基线（垂直对齐方式  ）</div><div class="line">   - top 文本的基线处于文本的正上方，并且有一段距离</div><div class="line">   - middle 文本的基线处于文本的正中间</div><div class="line">   - bottom 文本的基线处于文本的证下方，并且有一段距离</div><div class="line">   - hanging 文本的基线处于文本的正上方，并且和文本粘合</div><div class="line">   - alphabetic 默认值，基线处于文本的下方，并且穿过文字</div><div class="line">   - ideographic 和bottom相似，但是不一样</div></pre></td></tr></table></figure>
</li>
<li><p>ctx.strokeText(str, 100, 100, 600);</p>
<ul>
<li>参数</li>
</ul>
<ol>
<li>x轴位置</li>
<li>y轴位置</li>
<li>最小宽度，大于这个宽度会被压缩</li>
</ol>
</li>
<li>获取文字的宽度 ctx.measureText(str).width</li>
<li>ctx.fillText(str, 100, 200);<ul>
<li>参数</li>
</ul>
<ol>
<li>x轴位置</li>
<li>y轴位置<br>代码：<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> canvas = <span class="built_in">document</span>.querySelector(<span class="string">'canvas'</span>);</div><div class="line">      <span class="keyword">var</span> ctx = canvas.getContext(<span class="string">'2d'</span>);</div><div class="line">      <span class="keyword">var</span> str = <span class="string">'我叫大白'</span>;</div><div class="line">      ctx.font = <span class="string">'40px 楷体'</span></div><div class="line">      ctx.strokeStyle = <span class="string">'red'</span>;</div><div class="line">      <span class="comment">//左右对齐 基于坐标点</span></div><div class="line">      ctx.textAlign = <span class="string">'left'</span>;</div><div class="line">      <span class="comment">//上下对齐基于坐标点</span></div><div class="line">      ctx.textBaseline = <span class="string">'bottom'</span>;</div><div class="line">      <span class="comment">//参数 </span></div><div class="line">      <span class="comment">//1 x轴位置</span></div><div class="line">      <span class="comment">//2 y轴位置</span></div><div class="line">      <span class="comment">//3 最小宽度，大于这个宽度会被压缩</span></div><div class="line">      </div><div class="line">      <span class="comment">// 设置文本</span></div><div class="line">      ctx.strokeText(str, <span class="number">100</span>, <span class="number">100</span>, <span class="number">600</span>);</div><div class="line">      </div><div class="line">      <span class="comment">//绘制的文字下面的线条</span></div><div class="line">      ctx.moveTo(<span class="number">100</span>, <span class="number">100</span>);</div><div class="line">      ctx.lineTo(<span class="number">500</span>, <span class="number">100</span>);</div><div class="line">      ctx.stroke();</div><div class="line">      </div><div class="line">      <span class="comment">// 获取文字宽度</span></div><div class="line">      <span class="keyword">var</span> textWidth = ctx.measureText(str).width;</div><div class="line">      <span class="comment">// 绘制文字渐变</span></div><div class="line">      <span class="keyword">var</span> linearGradient = ctx.createLinearGradient(<span class="number">100</span>, <span class="number">200</span>, textWidth + <span class="number">100</span>, <span class="number">200</span>);</div><div class="line">      linearGradient.addColorStop(<span class="number">0</span>, <span class="string">'red'</span>);</div><div class="line">      linearGradient.addColorStop(<span class="number">0.5</span>, <span class="string">'green'</span>);</div><div class="line">      linearGradient.addColorStop(<span class="number">1</span>, <span class="string">'yellow'</span>);</div><div class="line">      ctx.fillStyle = linearGradient;</div><div class="line">      ctx.fillText(str, <span class="number">100</span>, <span class="number">200</span>);</div></pre></td></tr></table></figure>
</li>
</ol>
</li>
</ul>
<h3 id="绘制图片"><a href="#绘制图片" class="headerlink" title="绘制图片"></a>绘制图片</h3><ul>
<li>一共三种方法 方法是同一方法，传的参数不同意义也就不同</li>
</ul>
<ol>
<li><p>ctx.drawImage(img, x, y)</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">参数：</div><div class="line">   图片对象</div><div class="line">   绘制的坐标轴 x 轴</div><div class="line">   绘制的坐标轴 y 轴</div><div class="line">   ctx.drawImage(img, 100, 100);</div></pre></td></tr></table></figure>
</li>
<li><p>ctx.drawImage(img, x, y, width, height)</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">参数：</div><div class="line">    图片对象</div><div class="line">    绘制的坐标轴 x 轴</div><div class="line">    绘制的坐标轴 y 轴</div><div class="line">    绘制图片的宽度</div><div class="line">    绘制图片的高度</div><div class="line">   ctx.drawImage(img, 100, 100, 300, 200);</div></pre></td></tr></table></figure>
</li>
<li><p>ctx.drawImage(img, Cx, Cy, width, height,x,y,Cwidth,Cheight)</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">  参数：</div><div class="line">   img： 图片对象</div><div class="line">    Cx: 图片的上的定位 x 轴 ---在图片上定位，从图片的什么位置开始显示</div><div class="line">    Cy: 图片的上的定位 y 轴</div><div class="line"> width: 截取图片显示出现的大小 x 轴  ---将这么大范围的图片 显示在绘制图片的大小中</div><div class="line">height: 截取图片显示出现的大小 y 轴</div><div class="line">     x: 绘制的坐标轴 x 轴   ---在画布定位的位置上进行显示</div><div class="line">     y: 绘制的坐标轴 y 轴</div><div class="line">Cwidth: 绘制图片显示的宽度   ---在画布上显示的多大的框，用来显示图片</div><div class="line">Cheight: 绘制图片显示的高度</div><div class="line">     ctx.drawImage(img, 400, 100, 500, 500, 100, 100, 200, 200);</div></pre></td></tr></table></figure>
</li>
</ol>
<p>以下是实现的代码：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div></pre></td><td class="code"><pre><div class="line">&lt;script&gt;</div><div class="line">        <span class="keyword">var</span> canvas = <span class="built_in">document</span>.querySelector(<span class="string">'canvas'</span>);</div><div class="line">        <span class="keyword">var</span> ctx = canvas.getContext(<span class="string">'2d'</span>);</div><div class="line">        <span class="keyword">var</span> img = <span class="keyword">new</span> Image();</div><div class="line">        img.onload = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</div><div class="line">            <span class="comment">//图片对象</span></div><div class="line">            <span class="comment">//绘制的坐标轴 x 轴</span></div><div class="line">            <span class="comment">//绘制的坐标轴 y 轴</span></div><div class="line">            <span class="comment">// ctx.drawImage(img, 100, 100);</span></div><div class="line"></div><div class="line">            <span class="comment">// 图片对象</span></div><div class="line">            <span class="comment">// 绘制的坐标轴 x 轴</span></div><div class="line">            <span class="comment">// 绘制的坐标轴 y 轴</span></div><div class="line">            <span class="comment">// 绘制图片的宽度</span></div><div class="line">            <span class="comment">// 绘制图片的高度</span></div><div class="line">            <span class="comment">// ctx.drawImage(img, 100, 100, 300, 200);</span></div><div class="line"></div><div class="line">            <span class="comment">// 图片对象</span></div><div class="line">            <span class="comment">// 图片的上的定位 x 轴 ---在图片上定位，从图片的什么位置开始显示</span></div><div class="line">            <span class="comment">// 图片的上的定位 y 轴</span></div><div class="line">            <span class="comment">// 截取图片显示出现的大小 x 轴  ---将这么大范围的图片 显示在绘制图片的大小中</span></div><div class="line">            <span class="comment">// 截取图片显示出现的大小 y 轴</span></div><div class="line">            <span class="comment">// 绘制的坐标轴 x 轴   ---在画布定位的位置上进行显示</span></div><div class="line">            <span class="comment">// 绘制的坐标轴 y 轴</span></div><div class="line">            <span class="comment">// 绘制图片显示的宽度   ---在画布上显示的多大的框，用来显示图片</span></div><div class="line">            <span class="comment">// 绘制图片显示的高度</span></div><div class="line">            ctx.drawImage(img, <span class="number">400</span>, <span class="number">100</span>, <span class="number">500</span>, <span class="number">500</span>, <span class="number">100</span>, <span class="number">100</span>, <span class="number">200</span>, <span class="number">200</span>);</div><div class="line">        &#125;</div><div class="line">        img.src = <span class="string">'image/1.jpg'</span></div><div class="line">    &lt;<span class="regexp">/script&gt;</span></div></pre></td></tr></table></figure>
<h3 id="帧动画与补间动画的区别"><a href="#帧动画与补间动画的区别" class="headerlink" title="帧动画与补间动画的区别"></a>帧动画与补间动画的区别</h3><hr>
<ul>
<li>帧就是一个静止的画面，视频一般一秒是25帧</li>
<li>帧动画是在事件帧上一帧一帧的画，过程比较细腻，比较灵活，占用内存大</li>
<li>补间动画：只需要为动画的第一个关键帧和最后一个关键帧创建内容，其余的内容有Flash自动生成，占用内存小</li>
</ul>
<hr>
<p>下面是网上解释:</p>
<ul>
<li>逐帧动画是在时间帧上逐帧绘制帧内容，由于是一帧一帧的画，所以逐帧动画具有非常大的灵活性，几乎可以表现任何想表现的内容。 </li>
<li>由于逐帧动画的帧序列内容不一样，不仅增加制作负担而且最终输出的文件量也很大，但它的优势也很明显：因为它相似与电影播放模式，很适合于表演很细腻的动画，如3D效果、人物或动物急剧转身等等效果。</li>
<li>与逐帧动画相比，补间动画具有以下几个特点：首先，制作方法简单方便。只需要为动画的第一个关键帧和最后一个关键帧创建内容，两个关键帧之间帧的内容由Flash自动生成，不需要人为处理。其次，相对于逐帧动画来说，补间动画更为连贯自然。因为逐帧动画是由手工控制，帧与帧之间的过渡很可能会不自然、不连贯，而补间动画除了两个关键帧由手工控制外，中间的帧都由Flash自动生成，技术含量很高，因此过渡更为自然连贯。最后，相对于逐帧动画来说，补间动画的文件更小，占用内存少。</li>
</ul>
<hr>
<h3 id="变形转换"><a href="#变形转换" class="headerlink" title="变形转换"></a>变形转换</h3><h4 id="translate-x-y-移动的是坐标轴"><a href="#translate-x-y-移动的是坐标轴" class="headerlink" title="translate(x, y) -移动的是坐标轴"></a>translate(x, y) -移动的是坐标轴</h4><hr>
<p>translate 方法接受两个参数。x 是左右偏移量，y 是上下偏移量，如右图所示。</p>
<hr>
<p><img src="https://developer.mozilla.org/@api/deki/files/85/=Canvas_grid_translate.png" alt="image"></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">&lt;script&gt;</div><div class="line">        <span class="keyword">var</span> canvas = <span class="built_in">document</span>.querySelector(<span class="string">'canvas'</span>);</div><div class="line">        <span class="keyword">var</span> ctx = canvas.getContext(<span class="string">'2d'</span>);</div><div class="line">        <span class="comment">// 移动的是坐标轴 </span></div><div class="line">        <span class="comment">// 参数 x 轴坐标</span></div><div class="line">        <span class="comment">// y 轴坐标</span></div><div class="line">        ctx.translate(<span class="number">300</span>, <span class="number">200</span>);</div><div class="line">        ctx.strokeRect(<span class="number">10</span>, <span class="number">10</span>, <span class="number">100</span>, <span class="number">100</span>);</div><div class="line">&lt;<span class="regexp">/script&gt;</span></div></pre></td></tr></table></figure>
<h4 id="rotate-angle-以原点为中心旋转-canvas"><a href="#rotate-angle-以原点为中心旋转-canvas" class="headerlink" title="rotate(angle) -以原点为中心旋转 canvas"></a>rotate(angle) -以原点为中心旋转 canvas</h4><hr>
<p>这个方法只接受一个参数：旋转的角度(angle)，它是顺时针方向的，以弧度为单位的值。</p>
<h2 id="旋转的中心点始终是-canvas-的原点，如果要改变它，我们需要用到-translate-方法。"><a href="#旋转的中心点始终是-canvas-的原点，如果要改变它，我们需要用到-translate-方法。" class="headerlink" title="旋转的中心点始终是 canvas 的原点，如果要改变它，我们需要用到 translate 方法。"></a>旋转的中心点始终是 canvas 的原点，如果要改变它，我们需要用到 translate 方法。</h2><p><img src="https://developer.mozilla.org/@api/deki/files/84/=Canvas_grid_rotate.png" alt="image"></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">&lt;script&gt;</div><div class="line">        <span class="keyword">var</span> canvas = <span class="built_in">document</span>.querySelector(<span class="string">'canvas'</span>);</div><div class="line">        <span class="keyword">var</span> ctx = canvas.getContext(<span class="string">'2d'</span>);</div><div class="line">         <span class="comment">//旋转过后 坐标轴发生改变 默认绕着坐标原点进行旋转</span></div><div class="line">        <span class="comment">//参数是弧度</span></div><div class="line">        ctx.rotate(<span class="built_in">Math</span>.PI / <span class="number">60</span>);</div><div class="line">        ctx.strokeRect(<span class="number">10</span>, <span class="number">10</span>, <span class="number">100</span>, <span class="number">100</span>);</div><div class="line">&lt;<span class="regexp">/script&gt;</span></div></pre></td></tr></table></figure>
<h4 id="scale-x-y-对形状，位图进行缩小或者放大。"><a href="#scale-x-y-对形状，位图进行缩小或者放大。" class="headerlink" title="scale(x, y) -对形状，位图进行缩小或者放大。"></a>scale(x, y) -对形状，位图进行缩小或者放大。</h4><hr>
<ol>
<li>scale 方法接受两个参数。x,y 分别是横轴和纵轴的缩放因子，它们都必须是正值。值比 1.0 小表示缩小，比 1.0 大则表示放大，值为 1.0 时什么效果都没有。</li>
<li>默认情况下，canvas 的 1 单位就是 1 个像素。举例说，如果我们设置缩放因子是 0.5，1 个单位就变成对应 0.5 个像素，这样绘制出来的形状就会是原先的一半。同理，设置为 2.0 时，1 个单位就对应变成了 2 像素，绘制的结果就是图形放大了 2 倍。</li>
</ol>
<hr>
<p><img src="/img/scale.jpg" alt="image"></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">&lt;script&gt;</div><div class="line">        <span class="keyword">var</span> canvas = <span class="built_in">document</span>.querySelector(<span class="string">'canvas'</span>);</div><div class="line">        <span class="keyword">var</span> ctx = canvas.getContext(<span class="string">'2d'</span>);</div><div class="line">       <span class="comment">//缩放 缩放的是坐标轴</span></div><div class="line">        <span class="comment">// 参数 </span></div><div class="line">        <span class="comment">// x 轴缩放  </span></div><div class="line">        <span class="comment">// y 轴缩放  </span></div><div class="line">        <span class="comment">// ctx.scale(1, 2);</span></div><div class="line">        ctx.font = <span class="string">'40px 宋体'</span>;</div><div class="line">        ctx.scale(<span class="number">2</span>, <span class="number">2</span>);</div><div class="line">        ctx.strokeText(<span class="string">'你好'</span>,<span class="number">100</span>,<span class="number">100</span>,<span class="number">600</span>);</div><div class="line">        ctx.fillText(<span class="string">'你好'</span>, <span class="number">100</span>, <span class="number">150</span>);</div><div class="line">&lt;<span class="regexp">/script&gt;</span></div></pre></td></tr></table></figure>
<h3 id="保护和恢复-save-restore"><a href="#保护和恢复-save-restore" class="headerlink" title="保护和恢复 -save()restore()"></a>保护和恢复 -save()restore()</h3><ul>
<li>save 和 restore 方法是用来保存和恢复 canvas 状态的，都没有参数。</li>
<li>数据存储类型是栈；先进后出</li>
<li>存储一系列样式</li>
<li>存储数据方式<br><img src="/img/save.jpg" alt="image"></li>
<li>恢复数据<br><img src="/img/restore.jpg" alt="image"></li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div></pre></td><td class="code"><pre><div class="line">&lt;canvas width=<span class="string">'600'</span> height=<span class="string">'800'</span>&gt;<span class="xml"><span class="tag">&lt;/<span class="name">canvas</span>&gt;</span></span></div><div class="line">    &lt;script&gt;</div><div class="line">        <span class="keyword">var</span> canvas = <span class="built_in">document</span>.querySelector(<span class="string">'canvas'</span>);</div><div class="line">        <span class="keyword">var</span> ctx = canvas.getContext(<span class="string">'2d'</span>);</div><div class="line"></div><div class="line"></div><div class="line">        <span class="comment">//数据存储类型是栈；先进后出</span></div><div class="line">        <span class="comment">//存储一系列样式</span></div><div class="line">        <span class="comment">//全取出以后 恢复的是第一个存储的样式</span></div><div class="line">        ctx.moveTo(<span class="number">100</span>, <span class="number">100</span>);</div><div class="line">        ctx.lineTo(<span class="number">200</span>, <span class="number">100</span>);</div><div class="line">        ctx.strokeStyle = <span class="string">'red'</span>;</div><div class="line">        ctx.lineWidth = <span class="number">10</span>;</div><div class="line">        ctx.save();</div><div class="line">        ctx.stroke();</div><div class="line"></div><div class="line">        ctx.beginPath();</div><div class="line">        ctx.moveTo(<span class="number">100</span>, <span class="number">200</span>);</div><div class="line">        ctx.lineTo(<span class="number">200</span>, <span class="number">200</span>);</div><div class="line">        ctx.strokeStyle = <span class="string">'green'</span>;</div><div class="line">        ctx.lineWidth = <span class="number">20</span>;</div><div class="line">        ctx.save()</div><div class="line">        ctx.stroke();</div><div class="line"></div><div class="line">        ctx.beginPath();</div><div class="line">        ctx.moveTo(<span class="number">100</span>, <span class="number">300</span>);</div><div class="line">        ctx.lineTo(<span class="number">200</span>, <span class="number">300</span>);</div><div class="line">        <span class="comment">// ctx.strokeStyle = 'red';</span></div><div class="line">        <span class="comment">// ctx.lineWidth = 10;</span></div><div class="line">        ctx.restore();</div><div class="line">        ctx.stroke();</div><div class="line"></div><div class="line">        ctx.beginPath();</div><div class="line">        ctx.moveTo(<span class="number">100</span>, <span class="number">400</span>);</div><div class="line">        ctx.lineTo(<span class="number">200</span>, <span class="number">400</span>);</div><div class="line">        <span class="comment">// ctx.strokeStyle = 'red';</span></div><div class="line">        <span class="comment">// ctx.lineWidth = 10;</span></div><div class="line">        ctx.restore();</div><div class="line">        ctx.stroke();</div><div class="line"></div><div class="line"></div><div class="line">        ctx.beginPath();</div><div class="line">        ctx.moveTo(<span class="number">100</span>, <span class="number">500</span>);</div><div class="line">        ctx.lineTo(<span class="number">200</span>, <span class="number">500</span>);</div><div class="line">        <span class="comment">// ctx.strokeStyle = 'red';</span></div><div class="line">        <span class="comment">// ctx.lineWidth = 10;</span></div><div class="line">        ctx.restore();</div><div class="line">        ctx.stroke();</div><div class="line">    &lt;<span class="regexp">/script&gt;</span></div></pre></td></tr></table></figure>
<h3 id="层级-globalCompositeOperation"><a href="#层级-globalCompositeOperation" class="headerlink" title="层级 globalCompositeOperation"></a>层级 globalCompositeOperation</h3><ul>
<li>ctx.globalCompositeOperation = ‘属性值’;<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">source-over	    默认。在目标图像上显示源图像。</div><div class="line">source-atop	    在目标图像顶部显示源图像。源图像位于目标图像之外的部分是不可见的。</div><div class="line">source-in	    在目标图像中显示源图像。只有目标图像内的源图像部分会显示，目标图像是透明的。</div><div class="line">source-out	    在目标图像之外显示源图像。只会显示目标图像之外源图像部分，目标图像是透明的。</div><div class="line">destination-over    在源图像上方显示目标图像。</div><div class="line">destination-atop    在源图像顶部显示目标图像。源图像之外的目标图像部分不会被显示。</div><div class="line">destination-in	    在源图像中显示目标图像。只有源图像内的目标图像部分会被显示，源图像是透明的。</div><div class="line">destination-out	    在源图像外显示目标图像。只有源图像外的目标图像部分会被显示，源图像是透明的。</div><div class="line">lighter	            显示源图像 + 目标图像。</div><div class="line">copy	            显示源图像。忽略目标图像。</div><div class="line">xor	            使用异或操作对源图像与目标图像进行组合。</div></pre></td></tr></table></figure></li>
</ul>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/canvas/" rel="tag"># canvas</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/07/选择器/" rel="next" title="CSS选择器">
                <i class="fa fa-chevron-left"></i> CSS选择器
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/20/cookie和sesson/" rel="prev" title="cookie和session">
                cookie和session <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="http://dynamic-image.yesky.com/300x-/uploadImages/upload/20140912/upload/201409/wylnwjynkxijpg.jpg"
               alt="shine-wl" />
          <p class="site-author-name" itemprop="name">shine-wl</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
            
              <a href="/archives/">
            
                <span class="site-state-item-count">21</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              
                <span class="site-state-item-count">15</span>
                <span class="site-state-item-name">标签</span>
              
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#什么是canvas"><span class="nav-number">1.</span> <span class="nav-text">什么是canvas</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#canvas中的方法和属性"><span class="nav-number">2.</span> <span class="nav-text">canvas中的方法和属性</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#绘制的基本步骤"><span class="nav-number">3.</span> <span class="nav-text">绘制的基本步骤</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#绘制线条"><span class="nav-number">4.</span> <span class="nav-text">绘制线条</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#设置样式"><span class="nav-number">4.1.</span> <span class="nav-text">设置样式</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ctx-beginPath-开辟新的路径"><span class="nav-number">4.2.</span> <span class="nav-text">ctx.beginPath() 开辟新的路径</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#绘制三角形"><span class="nav-number">4.3.</span> <span class="nav-text">绘制三角形</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#ctx-closePath-关闭路径"><span class="nav-number">4.3.1.</span> <span class="nav-text">ctx.closePath() 关闭路径</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#填充-ctx-fill"><span class="nav-number">4.4.</span> <span class="nav-text">填充 ctx.fill()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#线两端的样式和线拐点的样式"><span class="nav-number">4.5.</span> <span class="nav-text">线两端的样式和线拐点的样式</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#绘制虚线"><span class="nav-number">4.6.</span> <span class="nav-text">绘制虚线</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#绘制矩形"><span class="nav-number">5.</span> <span class="nav-text">绘制矩形</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#ctx-rect-100-100-200-100"><span class="nav-number">5.1.</span> <span class="nav-text">ctx.rect(100,100,200,100);</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ctx-strokeRect-100-100-200-100"><span class="nav-number">5.2.</span> <span class="nav-text">ctx.strokeRect(100,100,200,100);</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ctx-fillRect-100-100-200-100"><span class="nav-number">5.3.</span> <span class="nav-text">ctx.fillRect(100,100,200,100);</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ctx-clearRect-0-0-600-400-清除矩形"><span class="nav-number">5.4.</span> <span class="nav-text">ctx.clearRect(0, 0, 600, 400); 清除矩形</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#绘制渐变"><span class="nav-number">6.</span> <span class="nav-text">绘制渐变</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#createLinearGradient"><span class="nav-number">6.1.</span> <span class="nav-text">createLinearGradient()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#addColorStop"><span class="nav-number">6.2.</span> <span class="nav-text">addColorStop()</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#绘制曲线"><span class="nav-number">7.</span> <span class="nav-text">绘制曲线</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#绘制圆弧"><span class="nav-number">8.</span> <span class="nav-text">绘制圆弧</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#绘制文字"><span class="nav-number">9.</span> <span class="nav-text">绘制文字</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#绘制图片"><span class="nav-number">10.</span> <span class="nav-text">绘制图片</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#帧动画与补间动画的区别"><span class="nav-number">11.</span> <span class="nav-text">帧动画与补间动画的区别</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#变形转换"><span class="nav-number">12.</span> <span class="nav-text">变形转换</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#translate-x-y-移动的是坐标轴"><span class="nav-number">12.1.</span> <span class="nav-text">translate(x, y) -移动的是坐标轴</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#rotate-angle-以原点为中心旋转-canvas"><span class="nav-number">12.2.</span> <span class="nav-text">rotate(angle) -以原点为中心旋转 canvas</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#旋转的中心点始终是-canvas-的原点，如果要改变它，我们需要用到-translate-方法。"><span class="nav-number"></span> <span class="nav-text">旋转的中心点始终是 canvas 的原点，如果要改变它，我们需要用到 translate 方法。</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#scale-x-y-对形状，位图进行缩小或者放大。"><span class="nav-number">0.1.</span> <span class="nav-text">scale(x, y) -对形状，位图进行缩小或者放大。</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#保护和恢复-save-restore"><span class="nav-number">1.</span> <span class="nav-text">保护和恢复 -save()restore()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#层级-globalCompositeOperation"><span class="nav-number">2.</span> <span class="nav-text">层级 globalCompositeOperation</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">shine-wl</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动</div>

  <span class="post-meta-divider">|</span>

  <div class="theme-info">主题 &mdash; <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.2</div>


        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.2"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.2"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  








  





  

  

  

  

  

  

</body>
</html>
